include Makefile.in

PRODUCT_NAME = Illuminator
BUNDLE_NAME = $(PRODUCT_NAME).app
SOURCES = $(foreach sdir,$(SRC_DIRS),$(wildcard $(sdir)/*.m))
OBJECTS = $(foreach file,$(patsubst %.m,%.o,$(SOURCES)),$(file))
VERSION = `cat VERSION`r`svn info | grep Revision | cut -d \: -f 2 | cut -d \  -f 2`

INFOPLIST_FILE = Info.plist
PNGS = art

EXECUTABLE_NAME = $(PRODUCT_NAME)

all: prepare $(PRODUCT_NAME)

prepare:
	@echo "#define VERSION @\"${VERSION}\"" > src/version.h

$(PRODUCT_NAME):
	@for dir in ${SRC_DIRS} ; do ( cd $$dir ; ${MAKE} ) ; done
	@mkdir -p build
	$(LD) $(LDFLAGS) -o build/$(EXECUTABLE_NAME) $(OBJECTS)

bundle: all
	mkdir -p $(BUNDLE_NAME)
	mkdir -p $(BUNDLE_NAME)/Russian.lproj
	mkdir -p $(BUNDLE_NAME)/English.lproj
	cp $(INFOPLIST_FILE) $(BUNDLE_NAME)/
	svn --force export $(PNGS) $(BUNDLE_NAME)/
	cp build/$(EXECUTABLE_NAME) $(BUNDLE_NAME)/
	cp PkgInfo $(BUNDLE_NAME)/
	cp Russian.lproj/Localizable.strings $(BUNDLE_NAME)/Russian.lproj/
	cp English.lproj/Localizable.strings $(BUNDLE_NAME)/English.lproj/

repo: bundle
	zip -g -r $(PRODUCT_NAME)-$(VERSION).zip $(BUNDLE_NAME)

.PHONY : clean
clean:
	@for dir in ${SRC_DIRS} ; do ( cd $$dir ; ${MAKE} clean ) ; done
	rm -rf build
	rm -rf $(BUNDLE_NAME)
	rm -f *.zip
	rm -f *~
